#include <glib.h>

static void _queue_foreach_func(gpointer data, gpointer       user_data)
{
    g_print("user_data:%s, data:%d \n", (gchar *)user_data, GPOINTER_TO_INT(data));
}

gint main(gint argc, gchar **argv)
{
    GQueue *q = NULL;
    gboolean empty = TRUE;
    guint len = 0;
    GList *node[3] = {NULL, NULL, NULL};

    q = g_queue_new();

    empty = g_queue_is_empty(q);
    len = g_queue_get_length(q);
    g_print("empty=%s, len=%d \n", empty ? "TRUE":"FALSE", len);

    g_queue_push_head(q, GINT_TO_POINTER(1));
    g_queue_push_tail(q, GINT_TO_POINTER(3));
    g_queue_push_nth(q, GINT_TO_POINTER(2), 1);
    // result: 1-2-3

    node[0] = g_new0(GList, 1);
    node[0]->data = GINT_TO_POINTER(7);
    node[1] = g_new0(GList, 1);
    node[1]->data = GINT_TO_POINTER(8);
    node[2] = g_new0(GList, 1);
    node[2]->data = GINT_TO_POINTER(9);

    g_queue_push_head_link(q, node[0]);
    g_queue_push_tail_link(q, node[1]);
    g_queue_push_nth_link(q, 1, node[2]);
    // result: 7-9-1-2-3-8

    g_queue_foreach(q, _queue_foreach_func, "Queue");
    
    empty = g_queue_is_empty(q);
    len = g_queue_get_length(q);
    g_print("empty=%s, len=%d \n", empty ? "TRUE":"FALSE", len);

    //g_list_free(node[0]);
    //g_list_free(node[1]);
    //g_list_free(node[2]);
    g_queue_free(q);

    return 0;
}